//
//  BKTwoCollectionViewCell.m
//  FastBee
//
//  Created by mac on 16/9/11.
//  Copyright © 2016年 xbk. All rights reserved.
//

#import "BKTwoCollectionViewCell.h"
#import "masonry.h"
#import "UIView+MDRExtension.h"
#import "UIImageView+WebCache.h"


@interface BKTwoCollectionViewCell()

@property (nonatomic,weak) UIImageView *pict;
@property (nonatomic,weak) UILabel *nameLabel;
@property (nonatomic,weak) UILabel *box;
@property (nonatomic,weak) UILabel *nowLabel;
@property (nonatomic,weak) UILabel *beforeLabel;

@end

@implementation BKTwoCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}


- (void)setModel:(BKTwoCollectionModel *)model{

    _model = model;
    [self.pict sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil];
    self.nameLabel.text = model.name;
    self.box.text = model.specifics;
    self.beforeLabel.text = model.market_price;
    self.nowLabel.text = model.partner_price;
}

- (void)setupUI{
    
    //添加图片控件
    UIImageView *pict = [[UIImageView alloc]init];
    pict.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:pict];
    
    [pict mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.width.equalTo(self.contentView);
        make.height.equalTo(@160);
    }];
    
    //添加商品名控件
    UILabel *nameLabel = [[UILabel alloc]init];
    [self.contentView addSubview:nameLabel];
    nameLabel.text = @"sssssss";
    nameLabel.font = [UIFont systemFontOfSize:13];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(5);
        make.top.equalTo(pict.mas_bottom);
        make.width.equalTo(self.contentView);
    }];
    
    //添加精选控件
    UIImageView *select = [[UIImageView alloc]init];
    [self.contentView addSubview:select];

    select.image = [UIImage imageNamed:@"jingxuan.png"];
    
    [select mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLabel.mas_bottom);
        make.left.equalTo(nameLabel);
        make.height.equalTo(@15);
        make.width.equalTo(@30);
    }];
    
    //添加精选控件
    UIImageView *buy = [[UIImageView alloc]init];
    [self.contentView addSubview:buy];
    buy.image = [UIImage imageNamed:@"buyOne.png"];
    
    [buy mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(select.mas_right).offset(5);
        make.top.equalTo(select);
        make.height.equalTo(@15);
        make.width.equalTo(@30);
    }];
    
    //添加多少钱每盒
    UILabel *box = [[UILabel alloc]init];
    [self.contentView addSubview:box];
    box.text = @"400/盒";
    box.font = [UIFont systemFontOfSize:14];
    [box mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(5);
        make.top.equalTo(select.mas_bottom);
        
    }];
    
    //现在价格
    UILabel *nowLabel = [[UILabel alloc]init];
    [self.contentView addSubview:nowLabel];
    nowLabel.text = @"9944";
    nowLabel.textColor = [UIColor redColor];
    
    [nowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(box);
        make.top.equalTo(box.mas_bottom);
    }];
    //以前价格
    UILabel *beforeLabel = [[UILabel alloc]init];
    [self.contentView addSubview:beforeLabel];
    beforeLabel.text = @"1999999";
    
    [beforeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(nowLabel.mas_right).offset(8);
        make.top.equalTo(nowLabel);
    }];
    
    //加号
    UIButton *plusBtn = [[UIButton alloc]init];
    [self.contentView addSubview:plusBtn];
    [plusBtn setImage:[UIImage imageNamed:@"increase"] forState:UIControlStateNormal];
    
    [plusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.contentView.mas_right).offset(-5);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
    }];
    
    /**
     *  @property (nonatomic,weak) UIImageView *pict;
     @property (nonatomic,weak) UILabel *nameLabel;
     @property (nonatomic,weak) UIImageView *select;
     @property (nonatomic,weak) UIImageView *buy;
     @property (nonatomic,weak) UILabel *box;
     @property (nonatomic,weak) UILabel *nowLabel;
     @property (nonatomic,weak) UILabel *beforeLabel;
     */
    
    _pict = pict;
    _nameLabel = nameLabel;
    _box = box;
    _nameLabel = nameLabel;
    _beforeLabel = beforeLabel;
    _nowLabel = nowLabel;
}

@end
